import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import fire from '@dfeidao/atom-web/msg/fire';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
interface Item {
	parent_no: string;
	formid: string;
}
export default async function a005(fd: IFeidaoAiBrowserComponent, args: { data: { data: { id: string, formid: string, client_type: string, form: string } } }) {
	const node = fd.data.node.querySelector<HTMLInputElement>('[listlist]');
	const arr = JSON.parse(node.getAttribute('v'));
	set(fd, 'formid', '');
	const aa = arr.filter((v: Item) => {
		return v.parent_no === args.data.data.id;
	});
	if (aa.length !== 0) {
		set(fd, 'dataFlag', 0);

	} else {
		set(fd, 'dataFlag', 1);
		let bb;
		if (args.data.data.formid) {
			bb = arr.filter((v: Item) => {
				return v.formid === args.data.data.formid;
			});
			if (bb.length === 1) {
				set(fd, 'formid', bb[0].formid);

			} else {
				set(fd, 'formid', '');
			}
		} else {
			set(fd, 'formid', '');
		}
	}

	args.data.data.form = get(fd, 'formid');
	set(fd, 'curr_dept', args.data.data);

	const menu_no = args.data.data.id;
	const productid = get(fd, 'productid');
	const client_type = args.data.data.client_type;

	fire('zj-000001', 'ec-009', { menu_no, productid, client_type });

}
